
import sys
arr=list(map(int,input().split()))

def getResult():
    minV=sys.maxsize
    minIdx=-1
    n=len(arr)-1
    for i in range(n,0,-1):
        if arr[i]!=-1:
            if i*2+1<=n and arr[i*2+1] !=-1:
                continue
            if i*2+2<=n and arr[i*2+2] !=-1:
                continue
            if minV>arr[i]:
                minV=arr[i]
                minIdx=i
    path=[]
    path.insert(0,str(minV))
    while minIdx!=0:
        f=(minIdx-1)//2
        path.insert(0,str(arr[f]))
        minIdx=f
    return " ".join(path)
print(getResult())
# 3 5 7 -1 -1 2 4
# 5 9 8 -1 -1 7 -1 -1 -1 -1 -1 6


